
$(function () {
   $('.view-details').click(function () {
      $(this).next().stop().slideToggle('fast');
      return true;
   });

   $('.buy-checkbox').click(function () {
      if($(this).attr('isSelect') == 'true') {
          $(this).addClass('unselect');
          $(this).removeClass('select');
          $(this).attr('isSelect', 'false');
      } else {
          $(this).addClass('select');
          $(this).removeClass('unselect');
          $(this).attr('isSelect', 'true');
      }
       sumMoney();
   });
   
   $('#buy').click(function () {
       var buyArr = $('.buy-checkbox');
       var selectNumber = 0;
       for(var i = 0; i < buyArr.length; i++) {
           if($(buyArr[i]).attr('isSelect') == 'true') {
               selectNumber ++;
           }
       }
       if(selectNumber > 0) {
         winTip('下单成功！', true);
       } else {
           winTip('别！还没选择食谱呢！', false);
       }
   });

   $('.deleteShopCat').click(function () {
      var cookbook = $(this).parent();
      cookbook.remove();
      shoppingCart($(this).attr('data'));
   });

});

function sumMoney() {
    var buyArr = $('.buy-checkbox');
    var sum = 0;
    for(var i = 0; i < buyArr.length; i++) {
        if($(buyArr[i]).attr('isSelect') == 'true') {
            var cookbook = $(buyArr[i]).parent().parent();
            var cookbookMoney = $(cookbook).find('.cookbookMoney').html();
            var cookbookNumber = $(cookbook).find('.cookbookNumber').val();
            sum += parseFloat(cookbookMoney) * parseFloat(cookbookNumber);
            console.info(cookbookMoney);
            console.info(cookbookNumber);
        }
    }
    $('#sumMoney').html(sum);
}